package com.angel.architecture.daos.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.angel.architecture.daos.UserDAO;
import com.angel.architecture.persistence.beans.User;
import com.angel.architecture.persistence.beans.UserRoles;
import com.angel.architecture.persistence.ids.ObjectId;
import com.angel.dao.generic.impl.GenericSpringHibernateDAO;

/**
 *
 * @author William
 * @since 08/April/2009
 *
 */
public class UserSpringHibernateDAO extends GenericSpringHibernateDAO<User, ObjectId> implements UserDAO {

    public UserSpringHibernateDAO(){
        super(User.class, ObjectId.class);
    }

    public Collection<User> findAllByUserRoles(UserRoles userRoles) {
        return super.findAll("roles", userRoles);
    }

    public Collection<User> findAllActives() {
        return super.findAll("active", Boolean.TRUE);
    }

    public Collection<User> findAllNonActives() {
        return super.findAll("active", Boolean.FALSE);
    }

    public User findUniqueByUserName(String username) {
        return super.findUnique("name", username);
    }

    public User findUniqueOrNullByUserNameAndPassword(String username, String password){
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("name", username);
        parameters.put("password", password);
        return super.findUniqueOrNull(parameters);
    }
}
